using System;
using System.Windows;

namespace LaplaceMeshDeformer
{
    /// <summary>
    /// 添加锚点对话框
    /// </summary>
    public partial class AddAnchorWindow : Window
    {
        public Vector3D CurrentPosition { get; private set; }
        public Vector3D NewPosition { get; private set; }

        public AddAnchorWindow(Vector3D currentPosition)
        {
            InitializeComponent();
            
            CurrentPosition = currentPosition;
            NewPosition = currentPosition;
            
            // 显示当前位置
            txtCurrentPosition.Text = $"({currentPosition.X:F3}, {currentPosition.Y:F3}, {currentPosition.Z:F3})";
            
            // 设置默认新位置
            txtX.Text = currentPosition.X.ToString("F3");
            txtY.Text = currentPosition.Y.ToString("F3");
            txtZ.Text = currentPosition.Z.ToString("F3");
        }

        private void BtnOK_Click(object sender, RoutedEventArgs e)
        {
            // 验证输入
            if (!double.TryParse(txtX.Text, out double x) ||
                !double.TryParse(txtY.Text, out double y) ||
                !double.TryParse(txtZ.Text, out double z))
            {
                MessageBox.Show("请输入有效的坐标值！", "输入错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            
            // 设置新位置
            NewPosition = new Vector3D(x, y, z);
            
            DialogResult = true;
            Close();
        }
    }
} 